package com.mlnx.netty.handler;


import com.mlnx.common.utils.MyLog;
import com.mlnx.data.entity.BpInfo;
import com.mlnx.device.entity.Device;
import com.mlnx.device.session.core.DeviceSession;
import com.mlnx.netty.base.handler.BaseSimpleChannelInboundHandler;
import com.mlnx.netty.base.message.XmbpCacheMessage;
import io.netty.channel.ChannelHandlerContext;

/**
 * Created by amanda.shan on 2019/4/1.
 */
public class XmbpCacheHandler extends BaseSimpleChannelInboundHandler<XmbpCacheMessage> {

    private MyLog log = MyLog.getLog(XmbpCacheHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, XmbpCacheMessage xmbpCacheMessage) throws Exception {
        DeviceSession session = (DeviceSession) sessionManager.getSession(ctx.channel());
        if(session!=null){
            Device device=deviceNettyService.getDevice(session.getClientId());
            for (BpInfo bpInfo:xmbpCacheMessage.getBpInfos()
                    ) {
                bpInfo.setDeviceId(session.getClientId());
                bpInfo.setPatientId(device.getPatientId());
                deviceBroadcastService.castBpInfo(bpInfo);
                log.info("广播离线血压数据："+bpInfo.toString());
            }
        }


    }
}
